function externalInit() {
	getDataset("userds").initialize();
	getDataset("userdsright").initialize();
	initDefaultDsData();
	getComponent("ltor").formRightData = function() {
		var userds = getDataset("userds");
		var userdsRight = getDataset("userdsright");
		var rows = userds.getSelectedRows();
		var addRows = new Array;
		if(rows != null) {
			for(var i = 0; i < rows.length; i ++) {
				if(rows[i].getCellValue(6) == "0"){
					var row = rows[i];
					var addRow = userdsRight.getEmptyRow();
					addRow.setCellValue(0, row.getCellValue(0));
					addRow.setCellValue(1, row.getCellValue(1));
					addRow.setCellValue(2, row.getCellValue(2));
					addRow.setCellValue(3, row.getCellValue(3));
					addRow.setCellValue(4, row.getCellValue(4));
					addRows.push(addRow);
				}
			}
		}
		return addRows;
	};
}
function initDefaultDsData(){
	var obj =  parent.window.assignparams;
	if(obj == null)
	    obj = parent.parent.window.assignparams;
	var assign_str = obj.toString();
	var dom = createXmlDom(assign_str);
	var rootNode = dom.documentElement;
	var roleList = rootNode.childNodes;
	var ds = getDataset("userds");
	var rowArr = new Array;
	if( roleList != null && roleList.length > 0){
		for(var i = 0; i < roleList.length; i ++){
			var role = roleList[i];
			var rolecode = "role_id_"+i;
			addRole(ds, rolecode,role.getAttribute("name"), rowArr);
			var userList = role.childNodes;
			if(userList != null && userList.length > 0){
				for(var k=0;k < userList.length; k++){
					var user = userList[k];
					addUser(ds, rolecode,user.childNodes, rowArr);
				}
			}
		}
	}
	ds.silent = true;
	ds.insertRows(0, rowArr, false);
	ds.silent = false;
	ds.setCurrentPage(ds.currentKey);
	return ds;
}

function addRole(ds, rolecode,rolename, rowArr){
	var row = ds.getEmptyRow();
	row.setCellValue(0, rolecode);
	row.setCellValue(1, rolename);
	//row.setCellValue(2, rolecode);
	//usertype
	row.setCellValue(6, "1");
	rowArr.push(row);
}
function addUser(ds, rolecode,nodes, rowArr){
	var row = ds.getEmptyRow();
	row.setCellValue(0,nodes[0].text);
	row.setCellValue(1,nodes[1].text);
	row.setCellValue(2,nodes[2].text);
	row.setCellValue(3,nodes[3].text);
	row.setCellValue(4,nodes[4].text);
	row.setCellValue(5,rolecode);
	row.setCellValue(6,"0");
	//ds.addRow(row,false); 
	rowArr.push(row);
}
function okForAssignFunction(){
	var rightDs = getDataset("userdsright");
	var count = rightDs.getRowCount();
	if(count == 0){
		showMessageDialog("请指派流程下已环节的参与者!");
		return ;
	}
	var pksArr = new Array();
	var index = rightDs.nameToIndex('pk_user');
	for(var i=0;i<count;i++){
		var pk = rightDs.getRow(i).getCellValue(index);
		pksArr.push(pk);
	}
	var type = getParameter("action");
	if(type == 'approve'){
		//如果是审批时需要指派，则将选择的pk放入window中
		parent.setAssPks2ApprovePage(pksArr);
	}else if(type == "commit"){
		//如果是保存提交时，则直接继续提交
		parent.billUI.eventHandler.JkbxSaveImpl(pksArr);
	}
	parent.hideDialog("assignable_info_dialog");
}
